package com.mjr.webmanage.controller;

import com.mjr.webmanage.pojo.Result;
import com.mjr.webmanage.util.AliyunOSSProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Slf4j
@RestController
public class UploadController {

    @Autowired
    private AliyunOSSProperties aliyunOSSProperties;


    @PostMapping("/upload")
    public Result upload(String username, Integer age, MultipartFile file) throws IOException {
        log.info("文件上传 username:{},age:{},file", username, age, file);


        log.info("文件上传 originalFilename:{}", aliyunOSSProperties);
        String originalFilename = file.getOriginalFilename();

        String substring = originalFilename.substring(originalFilename.lastIndexOf("."));

        String newFileName = UUID.randomUUID() + substring;


        file.transferTo(new File("D:/abc/" + newFileName));

        return Result.success();
    }
}
